/**
 * Copyright (C) Skywares Information Technology, LTD. 
 * All Rights Reserved.
 *
 * ResultCode.java created on 2020年1月23日 上午9:24:55 by Lyon Lu
 */
package com.mvc.server.result;

/**
 * <pre>
 * Description:
 * 	返回状态码
 * 	1000～1999 区间表示参数错误
 * 	2000～2999 区间表示用户错误
 * 	3000～3999 区间表示业务错误
 * 	5000～5999 区间表示服务端异常
 * @author Lyon Lu
 * @date 2020年1月23日 上午9:24:55
 *
 * </pre>
 */
public enum ResultCode {
	
	SUCCESS(0, "成功"),
	
	PARAM_IS_INVALID(1001, "参数无效"),
	PARAM_IS_BLANK(1002, "参数为空"),
	PARAM_TYPE_BIND_ERROR(1003, "参数类型错误"),
	PARAM_NOT_COMPLETE(1004, "参数缺失"),
	PARAM_BIND_ERROR(1005, "参数校验异常：%s"),
	VERIFY_CODE_ERROR(1006, "验证码错误"),
	
	USER_ACCOUNT_FORBIDDEN(2001, "账户已被禁用"),
	USER_NOT_EXIST(2002, "用户不存在"),
	USER_PASSWORD_ERROR(2003, "密码错误"),
	USER_SEEEION_ERROR(2004, "用户未登陆或登陆失效"),
	
	MIAOSHA_REPEATE(3000, "不能重复秒杀"),
	MIAOSHA_FAIL(3001, "秒杀失败"),
	MIAOSHA_OVER(3002, "商品已秒杀完毕"),
	MIAOSHA_QUEUING(3003, "秒杀排队中"),
	ACCESS_LIMIT_REACHED(3004, "服务端繁忙"),
	
	SERVER_ERROR(5000, "服务端异常"),
	SERVER_FALLBACK(5001, "服务调用熔断"),
	
	;
	
	private Integer code;
    private String message;
    
    ResultCode(Integer code, String message) 
    {
        this.code = code;
        this.message = message;
    }

	/**
	 * @return the code
	 */
	public Integer getCode() {
		return code;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(Integer code) {
		this.code = code;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	
	public ResultCode fillArgs(Object... args) {
		this.message = String.format(this.message, args);
		return this;
	}
}
